package com.wpp.dubbo.consume;

import com.wpp.dubbo.consume.service.ConsumerService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.*;

/**
 * @Classname MainClient
 * @Description
 * @Date 2021/1/20 21:31
 * @Created by wpp25
 */
public class MainClient {
    public static void main(String[] args) throws InterruptedException, IOException {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConsumerConfiguration.class);

        LinkedBlockingDeque linkedBlockingDeque = new LinkedBlockingDeque();
//        Executor executor = new ThreadPoolExecutor(1, 20, 2000L, TimeUnit.SECONDS, linkedBlockingDeque);
//        ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());

        ConsumerService consumerService = applicationContext.getBean(ConsumerService.class);
        System.in.read();
        while (true) {
            for (int i = 0; i < 3000; i++) {
                Thread.sleep(5);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        consumerService.method1();
                        consumerService.method2();
                        consumerService.method3();
                    }
                }).start();
            }
        }
    }

    @Configuration
    @PropertySource("classpath:/dubbo-consume.properties")
    @ComponentScan(basePackages = "com.wpp.dubbo.consume.service")
    @EnableDubbo
    static class ConsumerConfiguration {

    }
}
